package thread;
/**
 * 线程并发安全问题
 */
public class SyncDemo1 {
    public static void main(String[] args) {
        /*
        Shop shop = new Shop();
        Thread t1 = new Thread("王克晶"){
            public void run(){
                shop.buy();
            }
        };
        Thread t2 = new Thread("范传奇"){
            public void run(){
                shop.buy();
            }
        };

        Thread t1 = new Thread(shop::buy);
        Thread t2 = new Thread(shop::buy);
        t1.start();
        t2.start();
         */

        Shop shop1 = new Shop();
        Shop shop2 = new Shop();
        /*
        Thread t1 = new Thread("王克晶"){
            public void run(){
                shop1.buy();
            }
        };
        Thread t2 = new Thread("范传奇"){
            public void run(){
                shop2.buy();
            }
        };
        */
        Thread t1 = new Thread(shop1::buy); //方法引用
        Thread t2 = new Thread(shop2::buy);
        t1.start();
        t2.start();

    }
}












